# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=osgQtQuick
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}" "${MINGW_PACKAGE_PREFIX}-${_realname}-debug")
pkgver=2.0.0.8
pkgrel=1
pkgdesc="OpenSceneGraph QML Modules (mingw-w64)"
arch=('any')
license=('LGPL')
url="https://github.com/podsvirov/osgqtquick"
depends=("${MINGW_PACKAGE_PREFIX}-osgQt"
         "${MINGW_PACKAGE_PREFIX}-qt5")
makedepends=("make"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-osgQt-debug")
options=(!strip staticlibs !buildflags)
source=(${_realname}-${pkgver}.zip::https://github.com/podsvirov/osgqtquick/archive/v${pkgver}.zip)
sha256sums=('b56b2cd8749a806763896d898f86de4ef594dbc68fbe487f96eb0c7c868fb2fe')

build() {
  plain "No build step"
}

package_prog() {
  local _buildtype=${1}
  local _builddir=${_buildtype}-${MINGW_CHOST}

  if [[ "${_buildtype}" == "Debug" ]]; then
    depends=("${MINGW_PACKAGE_PREFIX}-osgQt-debug")
  fi

  [[ -d ${srcdir}/${_builddir} ]] && rm -rf ${srcdir}/${_builddir}
  mkdir -p ${srcdir}/${_builddir} && cd ${srcdir}/${_builddir}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=${_buildtype} \
    ../osgqtquick-${pkgver}

  make DESTDIR=${pkgdir} -j1 install

  if [[ "${_buildtype}" == "Debug" ]]; then
    rm -rf ${pkgdir}${MINGW_PREFIX}/include
    rm -rf ${pkgdir}${MINGW_PREFIX}/lib/cmake/osgQtQuick/osgQtQuickConfig.cmake
    rm -rf ${pkgdir}${MINGW_PREFIX}/lib/cmake/osgQtQuick/osgQtQuickConfigVersion.cmake
    rm -rf ${pkgdir}${MINGW_PREFIX}/lib/cmake/osgQtQuick/osgQtQuickTargets.cmake
    rm -rf ${pkgdir}${MINGW_PREFIX}/share/qt5/qml/*/qmldir
  fi
}

package_mingw-w64-i686-osgQtQuick() {
  package_prog Release
}

package_mingw-w64-i686-osgQtQuick-debug() {
  package_prog Debug
}

package_mingw-w64-x86_64-osgQtQuick() {
  package_prog Release
}

package_mingw-w64-x86_64-osgQtQuick-debug() {
  package_prog Debug
}
